<?php


namespace App\Api\Models;


class CmcGoodsCollection extends \Illuminate\Database\Eloquent\Model
{
    protected $table = 'cmc_goods_collections';

    //检验是否收藏
    static public function collection($gid,$uid)
    {
        return CmcGoodsCollection::where('goods_id',$gid)->where('uid',$uid)->count();
    }
    //检验收藏状态
    static public function statusCollection($gid,$uid)
    {
        return CmcGoodsCollection::where('goods_id',$gid)->where('uid',$uid)->get('status')->toArray()[0]['status'];
    }
    //添加收藏
    static public function add($data)
    {
        return CmcGoodsCollection::insert($data);
    }
    //确认&取消收藏
    static public function upCollection($id,$status)
    {
        return CmcGoodsCollection::where('id',$id)->update(['status'=>$status]);
    }

    //获取ID
    static public function getId($gid,$uid)
    {
        return CmcGoodsCollection::where('goods_id',$gid)->where('uid',$uid)->get('id')->toArray()[0]['id'];
    }
}